home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Toolbox / ProgressBars 1.0 / Sources / Initialize.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-17  |  2.7 KB  |  158 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Initialize.c
  3.     
  4.     Contains:    Initialization code for this application
  5.     
  6.     Written by:    Chris White, Developer Technical Support
  7.     
  8.     Copyright:    © 1996 by Apple Computer, Inc., all rights reserved.
  9.     
  10.     Change History (most recent first):
  11.     
  12.             1/22/96            CW        First release
  13.  
  14. */
  15.  
  16.  
  17. #pragma segment Initialize
  18.  
  19.  
  20.  
  21. // System includes
  22. #include <Resources.h>
  23. #include <Processes.h>
  24.  
  25. #ifndef __QUICKDRAW__
  26.     #include <Quickdraw.h>
  27. #endif
  28.  
  29. #ifndef __FONTS__
  30.     #include <Fonts.h>
  31. #endif
  32.  
  33. #ifndef __TEXTEDIT__
  34.     #include <TextEdit.h>
  35. #endif
  36.  
  37. #ifndef __DIALOGS__
  38.     #include <Dialogs.h>
  39. #endif
  40.  
  41. #ifndef __GESTALT__
  42.     #include <Gestalt.h>
  43. #endif
  44.  
  45. #ifndef __SEGLOAD__
  46.     #include <SegLoad.h>
  47. #endif
  48.  
  49. #ifndef __CODEFRAGMENTS__
  50.     #include <CodeFragments.h>
  51. #endif
  52.  
  53. #ifndef __THREADS__
  54.     #include <Threads.h>
  55. #endif
  56.  
  57.  
  58.  
  59.  
  60. // Application includes
  61.  
  62. #ifndef __BAREBONES__
  63.     #include "BareBones.h"
  64. #endif
  65.  
  66. #ifndef __PROTOTYPES__
  67.     #include "Prototypes.h"
  68. #endif
  69.  
  70.  
  71.  
  72. // static prototypes
  73. static Boolean CheckConfiguration ( void );
  74.  
  75.  
  76.  
  77.  
  78. void InitToolbox ( void )
  79. {    
  80.     
  81.     InitGraf ( &qd.thePort );
  82.     InitFonts ( );
  83.     InitWindows ( );
  84.     InitMenus ( );
  85.     TEInit ( );
  86.     InitDialogs ( nil );
  87.     InitCursor ( );
  88.     
  89.     FlushEvents ( everyEvent, 0 );
  90.     
  91.     return;
  92. }
  93.  
  94.  
  95.  
  96. void InitApplication ( void )
  97. {
  98.     SetMenuBar ( GetNewMBar ( kMenuBarID ) );
  99.     AppendResMenu ( GetMenuHandle ( kAppleMenu ), 'DRVR' );
  100.     DrawMenuBar ( );
  101.     
  102.     if ( !CheckConfiguration ( ) )
  103.     {
  104.         AlertUser ( kNeedSystem7, 0, nil );
  105.         ExitToShell ( );
  106.     }
  107.     
  108.     gQuit = false;                          // Initialize flag that controls main event loop
  109.     gSleepTime = kSleepTime;
  110.     
  111.     InstallAppleEventHandlers ( );
  112.     
  113.     AdjustMenus ( );
  114.     
  115.     // Create any RoutineDescriptors we may need
  116.     gOutlineUserItemUPP = NewUserItemProc ( OutlineUserItem );
  117.     
  118.     return;
  119. }
  120.  
  121.  
  122.  
  123. //
  124. // Verify that we can run on the current configuration
  125. //
  126. static Boolean CheckConfiguration ( void )
  127. {
  128.     SInt32        theResult;
  129.     OSErr        theErr;
  130.     Boolean        bHasAppleEvents;
  131.     
  132.     
  133.     
  134.     // We require AppleEvent Manager
  135.     theErr = Gestalt ( gestaltAppleEventsAttr, &theResult );
  136.     bHasAppleEvents = (theErr == noErr && (theResult & (1L << gestaltAppleEventsPresent)));
  137.     
  138.     // We would like the Thread Manager
  139.     theErr = Gestalt ( gestaltThreadMgrAttr, &theResult );
  140.     gHasThreadManager = (theErr == noErr && (theResult & (1L << gestaltThreadMgrPresent)));
  141.     
  142.     // It isn't enough to use Gestalt because we may not have successfully linked
  143.     // to the shared library. So, we also need to test one of the symbols from the
  144.     // library against kUnresolvedSymbol to make sure we have a valid connection
  145.     // to it. Things like memory limitations or someone having a library open with
  146.     // write permission could cause it to fail.
  147.     
  148. #if GENERATINGCFM
  149.     if ( gHasThreadManager )
  150.         gHasThreadManager = (NewThread != (void*) kUnresolvedCFragSymbolAddress);
  151. #endif
  152.     
  153.     
  154.     return bHasAppleEvents;
  155. }
  156.  
  157.  
  158.